﻿namespace AC.ExtendedRenderer.Toolkit.Charting
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    [ToolboxItem(true), ToolboxBitmap(typeof(DataBar))]
    public class DataBar : UserControl
    {
        private Color _colorBar;
        private int _value;
        private Container components;

        public DataBar()
        {
            this.InitializeComponent();
            this.BackColor = Color.Silver;
            this._value = 0;
            this._colorBar = Color.DarkBlue;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            base.Name = "DataBar";
            base.Size = new Size(0x80, 0x10);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle clientRectangle = base.ClientRectangle;
            e.Graphics.FillRectangle(new SolidBrush(this._colorBar), 0, 0, (clientRectangle.Width * this._value) / 100, clientRectangle.Height);
            base.OnPaint(e);
        }

        [Description("Gets or sets the current Bar Color in chart"), Category("Appearance")]
        public Color BarColor
        {
            get
            {
                return this._colorBar;
            }
            set
            {
                this._colorBar = value;
            }
        }

        [Category("Behavior"), Description("Gets or sets the current value in data bar")]
        public int Value
        {
            get
            {
                return this._value;
            }
            set
            {
                this._value = value;
                base.Invalidate();
            }
        }
    }
}

